<?php
/**
 * Created by PhpStorm.
 * User: jocky
 * Date: 2017/6/2
 * Time: 下午1:13
 */

namespace backend\controllers;

use common\controllers\BaseControllers;

class LogoutController extends BaseControllers
{

    public function actionIndex()
    {

        if (!\Yii::$app->user->isGuest) {
            $session = \Yii::$app->getSession();
            if (!YII_ENV_TEST) {
                $session->regenerateID(true);
            }

            $session->remove('uid');

            \Yii::$app->user->logout();
        }


        $isRender = \Yii::$app->request->get('isRender', 1);
        if ($isRender == 2) {
            exit(json_encode(['code' => 1, 'loginUrl' => \Yii::$app->user->loginUrl]));
        } else {
            $this->redirect(\Yii::$app->user->loginUrl);
        }
    }
}
